﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditCrmCallOn.aspx.cs"
    Inherits="ZX.WebApp.Crm.Customer.EditCrmCallOn" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.calendar.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <style type="text/css">/* Table样式 */body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; background: #eeeeee;}
       
       .yui-skin-sam table {
	    width: 100%;
        }
          
        .Contentbox
        {
        clear:both;
        margin-top:0px;
        border:1px solid #A8C29F;
        border-top:none;
        height:100%;
        text-align:left;
        padding-top:8px;
        }  .btn 
{ 
    border-right: #7b9ebd 1px solid; 
    padding-right: 3px; 
    border-top: #7b9ebd 1px solid; 
    padding-left: 3px; 
    font-size: 12px; 
    FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#cecfde); 
    border-left: #7b9ebd 1px solid; 
    cursor: hand; 
    color: black; 
    padding-top: 0px; 
    border-bottom: #7b9ebd 1px solid; 
    height:22px;
    vertical-align:top;
}
       </style>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <div class="fieldForm" id="fieldForm">
        <div class="Contentbox">
            <div id="toolbar" style="margin: 2px; padding-top: 100;">
    
                <button type="button" id="btnSave" name="btnSave">
                    保存退出</button>
                   <button type="reset" id ="btnFull" name="btnFull">重置</button>
                    <button type="button" id="btnClose" name="btnClose">
            退出</button>
            </div>
            <fieldset>
            <legend>&nbsp;工作记录明细</legend>
            <table class="tableContent">
                <tr>
                    <td width="100">
                        &nbsp;主题：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <input id="txtCaption" runat="server" name="txtCaption" maxlength="30" title="最多能输入30个字" type="text" style="width: 385px" /><span class="span_font"> 工作记录的主题，如：A产品成交纪实</span>
                    </td>  </tr><tr>
                    <td width="100">
                        &nbsp;客户选择：<span style="color: Red">*</span>
                    </td>
                    <td align="left">
                        <input type="hidden" id="CustomId" runat="server" name="CustomId" />
                        <input id="txtCustomId" runat="server" readonly="readonly" name="txtCustomId" type="text"
                            style="width: 349px" />
                        <button id="btnCustomId" name="L" type="button" class="btn">
                            选择</button><span class="span_font"> 选择您要接洽的客户</span>
                    </td>
                </tr>
                <tr>  <td width="100">&nbsp;动作类型：<span style="color: Red">*</span></td>
                    <td>
                      <asp:DropDownList ID="ddlAnimalType" runat="server" Width="87px">
                        <asp:ListItem Value="00000000-0000-0000-0000-000000000000">--请选择--</asp:ListItem>    
                        </asp:DropDownList><span class="span_font"> 您服务的动作类型</span>  </td>  </tr><tr>
                    <td width="100">
                        &nbsp;开始时间：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="FactStartDate" name="FactStartDate" style="width: 75px;" />
                            <asp:DropDownList ID="ddlStartMin" runat="server">
                        </asp:DropDownList>
                        <b>:</b>
                        <asp:DropDownList ID="ddlStartSec" runat="server">
                        </asp:DropDownList>-- <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="FactEndDate" name="FactEndDate" style="width: 75px;" />
                        <asp:DropDownList ID="ddlEndMin" runat="server">
                        </asp:DropDownList>
                        <b>:</b>
                        <asp:DropDownList ID="ddlEndSec" runat="server">
                        </asp:DropDownList><span class="span_font"> 工作的时间段(结束时间须小于当前时间)</span>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        &nbsp;联系人：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlLinkMan" runat="server" Width="87px">
                            <asp:ListItem Value="00000000-0000-0000-0000-000000000000">--请选择--</asp:ListItem>
                        </asp:DropDownList><span class="span_font"> 选择与您接洽客户的联系人</span>
                    </td>   </tr><tr>
                    <td width="100">
                        &nbsp;联系电话：
                    </td>
                    <td>
                        <asp:TextBox ID="txtPhone" runat="server" Enabled="false" Width="80px"></asp:TextBox><span class="span_font"> 联系人的电话，选择联系人时自动带出</span>
                    </td>
                </tr>
                
                <tr>
                   <td width="100">
                        &nbsp;预期结果：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="AnticipeResult" Width="385px" Rows="3" TextMode="MultiLine"
                            onKeyDown="showSetNum('AnticipeResult','spShow',1000)"  title="最多可输入1000个汉字" onKeyUp="showSetNum('AnticipeResult','spShow',1000)"  runat="server"></asp:TextBox><span id="spShow" class="span_font"> 预期结果，与客户接洽前的期望值</span>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        &nbsp;过程描述：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="txtCallContent" Width="385px" Rows="3" TextMode="MultiLine"
                            onKeyDown="showSetNum('txtCallContent','txtShow',1000)"  title="最多可输入1000个汉字" onKeyUp="showSetNum('txtCallContent','txtShow',1000)"  runat="server"></asp:TextBox><span id="txtShow" class="span_font"> 过程描述，与客户接洽的具体内容</span>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        &nbsp;完成情况：<span style="color: Red">*</span>
                    </td>
                    <td>
                        <asp:TextBox ID="Result" Width="385px" Rows="3" TextMode="MultiLine"
                            onKeyDown="showSetNum('Result','spResult',1000)"  title="最多可输入1000个汉字" onKeyUp="showSetNum('Result','spResult',1000)"  runat="server"></asp:TextBox><span id="spResult" class="span_font"> 完成情况，与客户接洽后的结果</span>
                    </td>
                </tr>
                <tr>
                   <td width="100">
                        &nbsp;备注：
                    </td>
                    <td>
                        <asp:TextBox ID="txtExplain" Rows="3" Width="385px"
                            onKeyDown="showSetNum('txtExplain','spExplain',200)"  title="最多可输入200个汉字" onKeyUp="showSetNum('txtExplain','spExplain',200)"  TextMode="MultiLine" runat="server"></asp:TextBox><span id="spExplain" class="span_font"> 备注,如：老板很大方，很平易近人</span>
                    </td>
                </tr>
                <tr>
                   <td width="100">
                        &nbsp;再来一条：
                    </td>
                    <td>
                           <input id="onceMore" name="onceMore" type="checkbox" /><span class="span_font"> 选中后，提交可以继续在本页面添加工作记录</span>
                    </td>
                </tr>
            </table>  </fieldset>
            <div class="fieldForm" id="">
                <div id="con_2">
                </div>
            </div>
        </div>
        <br />
        <fieldset>
            <legend>&nbsp;下一步：填写提醒消息</legend>
            <table class="tableContent">
                <tr>
                   <td width="100">
                        &nbsp;标题名称：
                    </td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server" MaxLength="30" title="最多可输入30个汉字" Width="385px"></asp:TextBox><span class="span_font"> 消息标题，如：5.1放假7天</span>
                    </td> </tr><tr>
                   <td width="100">
                       &nbsp;提醒时间：
                    </td>
                   <td>
                        <input runat="server" type="text" readonly="readonly" class="yui-date" dtype="D"
                            id="MessageTm" name="MessageTm" style="width: 80px;" />
                        <asp:DropDownList ID="ddlHour" runat="server">
                        </asp:DropDownList>
                        <b>:</b>
                        <asp:DropDownList ID="ddlMinute" runat="server">
                        </asp:DropDownList><span class="span_font"> 选择消息提醒的时间</span>
                    </td>
                </tr>
                <tr>
                    <td width="100">
                        &nbsp;内容：
                    </td>
                    <td>
                        <asp:TextBox ID="txtContent" Width="385px" Rows="3" onKeyDown="showSetNum('txtContent','spContent',100)" onKeyUp="showSetNum('txtContent','spContent',100)"  title="最多可输入100个汉字" TextMode="MultiLine" runat="server"></asp:TextBox><span id="spContent" class="span_font"> 消息内容，如：大家非常期待...</span>
                    </td>
                </tr>
            </table>
        </fieldset>
        <asp:HiddenField ID="ID" runat="server" />
        <asp:HiddenField ID="SaleadViser" runat="server" />
        <asp:HiddenField ID="AddUserId" runat="server" />
        <div id="dialog1" class="yui-pe-content">
            <div class="hd">
                客户选择</div>
            <div class="bd">
                <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                    margin: 0px; padding: 0px;"></iframe>
            </div>
        </div>
    </div>
    </form>
    <form id="form2" style="display: none" action="../../Extend/AjaxData/DataSave.aspx">
    <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    </form>
</body>
<script type="text/javascript">
 // function document.oncontextmenu() { event.returnValue = false; } //屏蔽鼠标右键
    var action = "<% =DataAction %>", condition = "";
    var entity = "<% =EntityName %>", EmptyData = "";
    //var url = "../../Extend/AjaxData/DataSave.aspx";
    var Url = "../../Extend/AjaxData/CustomOperating.aspx";
    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'top', height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                { position: 'center', body: 'fieldForm', gutter: '0 1 1 1', scroll: true }
            ]
            });
            layout.render();
        });
    })();
    YAHOO.example.init = function () {
        function onButtonClick(p_oEvent) {
            switch (this.get("id")) {
                case "btnSave":
                    fnSaveLinkRecord();
                    break;
                case "btnFull":
                    clearForm();
                    break;
                case "btnClose":
                    WinClose();
                    break;
                default:
                    break;
            }
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
            var btnSaves2 = new YAHOO.widget.Button("btnSave");
            btnSaves2.on("click", onButtonClick);
            var btnFull = new YAHOO.widget.Button("btnFull");
            btnFull.on("click", onButtonClick);
            var btnClose = new YAHOO.widget.Button("btnClose");
            btnClose.on("click", onButtonClick);
        });
    } ();
    /*客户选择对应的方法和ID*/
    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow1").src = src;
        YAHOO.example.container.dialog1.show();
    }
    //重置
    var clearForm = function () {
        location.reload(false)
    };
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        var handleSubmit = function () {
            var editwindow = document.getElementById("EditUIWindow1");
            if (editwindow) {
                editwindow.contentWindow.ChooseInfo();
                loadData();
            }
            YAHOO.example.container.dialog1.hide();
        };
        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					            { width: "650px",
					                height: "480px",
					                fixedcenter: true,
					                visible: false,
					                draggable: true,
					                close: true,
					                autofillheight: "body",
					                constraintoviewport: true,
					                buttons: [{ text: "确定", handler: handleSubmit, isDefault: true },
								            { text: "取消", handler: handleCancel}]
					            });
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog1.render();
        //拖动大小
        var resize = new YAHOO.util.Resize("dialog1", {
            handles: ["br"],
            autoRatio: false,
            minWidth: 650,
            minHeight: 450,
            status: false
        });
        resize.on("startResize", function (args) {
            if (this.cfg.getProperty("constraintoviewport")) {
                var D = YAHOO.util.Dom;
                var clientRegion = D.getClientRegion();
                var elRegion = D.getRegion(this.element);
                resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
                resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            } else {
                resize.set("maxWidth", null);
                resize.set("maxHeight", null);
            }
        }, YAHOO.example.container.dialog1, true);
        resize.on("resize", function (args) {
            var panelHeight = args.height;
            this.cfg.setProperty("height", panelHeight + "px");
        }, YAHOO.example.container.dialog1, true);
    });

    var loadData = function () {
        vid = document.getElementById("CustomId").value;
        var vc = "CustomId='" + vid + "'";
        LoadData1();
        YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=V_CrmActivityCall&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
//                EmptyData = str;
//                SetFormValue2(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
//加载数据
var LinkMan = [];
var LoadData1 = function () {
    var vc = "CustomId='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=CrmLinkMan&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {      
                var str = res.responseText;
                var obj = eval(str);
                LinkMan = obj;
                document.getElementById("ddlLinkMan").options.length = 0;
                if (obj[0].ID == undefined) {
                    alert("请先填写联系人");
                    parent.addTabs('新增联系人信息', '../Crm/Customer/EditCrmLinkMan.aspx?entity=CrmLinkMann&cid=' + vid); WinClose();
                }
                $("#txtPhone").val(obj[0].MobileTel);
                for (var i = 0; i < obj.length; i++) {
                    $("#ddlLinkMan").append("<option value='" + obj[i].ID + "'>" + obj[i].Caption + "</option>");
                }  
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
  $('#ddlLinkMan').change(function () {
      var vLinkMan = $('#ddlLinkMan').children('option:selected').val();
      if (LinkMan.length == 0) { loadData(); }
            for (var i = 0; i < LinkMan.length; i++) {
                if (LinkMan[i].ID == vLinkMan) {
                    $("#txtPhone").val(LinkMan[i].MobileTel);
                }
            }
    });

//  保存后关闭
    var WinClose = function () {
        try {
        parent.NeedRefreshPage.RefreshData();
        } catch (e) {
        window.parent.$("#tabs").tabs('close', '新增工作记录');
        window.parent.$("#tabs").tabs('close', '编辑工作记录');
        }
    window.parent.$("#tabs").tabs('close', '新增工作记录');
    window.parent.$("#tabs").tabs('close', '编辑工作记录');
};
var checkDate = function () {
    if ($('#txtCaption').val() == "") {
        alert("主题必须输入");
        $('#txtCaption').focus();
        return false;
    }
    if ($("#txtCustomId").val() == "") {
        alert("客户必须选择");
        $("#txtCustomId").focus();
        return false;
    }

    if ($('#ddlAnimalType').val() == "00000000-0000-0000-0000-000000000000") {
        alert("动作类型必须选择");
        $('#ddlAnimalType').focus();
        return false;
    }
    if ($('#FactStartDate').val() == "") {
        alert("开始时间不能为空");
        $('#FactStartDate').focus();
        return false;
    }
    if ($('#FactEndDate').val() == "") {
        alert("结束时间不能为空");
        $('#FactEndDate').focus();
        return false;
    }
    var endDate = "<%=strEndDate %>";
    if ($('#FactEndDate').val() > endDate) {
        alert("工作记录时段存在误填");
        $('#FactEndDate').focus();
        return false;
    }
    var fsm = $("#ddlStartMin").val();
    var fss = $("#ddlStartSec").val();
    var fem = $("#ddlEndMin").val();
    var fes = $("#ddlEndSec").val(); 
    if ($('#FactStartDate').val() > $('#FactEndDate').val()) {
        alert("结束时间不能小于开始时间");
        $('#FactEndDate').focus();
        return false;
    }
    if ($('#FactStartDate').val() == $('#FactEndDate').val()) {
        if (fsm > fem || (fsm == fem && fss >= fes)) {
            alert("结束时间不能小于开始时间");
            $('#FactEndDate').focus();
            return false;
        } 
    }
    if ($('#ddlLinkMan').val() == "00000000-0000-0000-0000-000000000000") {
        alert("联系人必须选择");
        $('#ddlLinkMan').focus();
        return false;
    }
    if ($('#AnticipeResult').val() == "") {
        alert("预期结果不能为空");
        $('#AnticipeResult').focus();
        return false;
    }
    if ($('#txtCallContent').val() == "") {
        alert("过程描述不能为空");
        $('#txtCallContent').focus();
        return false;
    }
    if ($('#Result').val() == "") {
        alert("预期结果完成情况不能为空");
        $('#Result').focus();
        return false;
    }
    return true;
}
var vid = $("#CustomId").val();   //客户ID
var fnSaveLinkRecord = function () {
    if (checkDate()) {
        var elist = [{ "Caption": ""}];
        elist[0].ID = $('#ID').val();
        elist[0].CustomId = vid;
        elist[0].Suject = $('#txtCaption').val();
        elist[0].TypeId = $("#ddlAnimalType").val();
        elist[0].LinkManID = $('#ddlLinkMan').val();
        var fsm = $("#ddlStartMin").val();
        var fss = $("#ddlStartSec").val();
        var fem = $("#ddlEndMin").val();
        var fes = $("#ddlEndSec").val();
        elist[0].PlanStartDate = $('#FactStartDate').val() + " " + fsm + ":" + fss + ":00";
        elist[0].PlanEndDate = $('#FactEndDate').val() + " " + fem + ":" + fes + ":00";
        elist[0].Contents = $('#txtCallContent').val();
        elist[0].AnticipeResult = $('#AnticipeResult').val();
        elist[0].Result = $('#Result').val();
        elist[0].Explain = $('#txtExplain').val();
        var ptime = document.getElementById("MessageTm").value + " " + document.getElementById("ddlHour").options[ddlHour.selectedIndex].value + ":" + document.getElementById("ddlMinute").options[ddlMinute.selectedIndex].value;
        var ptitle = document.getElementById("txtName").value;
        var pContent = document.getElementById("txtContent").value;
        var backc = ZX.WebApp.Crm.Customer.EditCrmActivity.Save(ptitle, pContent, ptime).value;
        var jsonStr = YAHOO.lang.JSON.stringify(elist);
        var SaveUrl = Url + "?r=" + Math.random() + "&action=procedure&entity=CrmActivityCall&json=" + encodeURI(jsonStr.replace(/&/g, "[A]").replace(/'/g, "''"));
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        if (document.getElementById("onceMore").checked) {
                            alert("数据保存成功");
                            clearForm();
                        } else {
                            alert("数据保存成功");
                            WinClose();
                        }
                    }
                    else {
                        alert(str + "\n" + "数据保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    } else {
        return;
    }
}
$(document).ready(function () {
    $('#MessageTm').cld();
    $('#FactStartDate').cld();
    $('#FactEndDate').cld();
});  
</script>
<script src="../../Scripts/yui.list.button.event.js" type="text/javascript"></script>
</html>
